<?php
  require_once('tpl/header.php');
?>
<?php
    require_once('../system/loginCheck.php');
    require_once('../system/dbConn.php');
    connect();
    ?>
    <h1>欢迎管理员<?php echo $_SESSION["adminname"]; ?>使用本系统</h1>
    <form>
    <input type="text" name="key">
    <input type="submit" value="搜索">
</form>
    <?php
    if (!isset($_GET["page"])) {
        $page=1;
    }
    else{
        $page=$_GET["page"];
    }

    $sql="select * from users";
    if (isset($_GET["key"])) {
    	$key=trim($_GET["key"]);
    	$sql="select * from users where uname like '%{$key}%'";
    }
    $result=mysql_query($sql);
    $num=mysql_num_rows($result);
    if ($num==0) {
    	echo "没有匹配的对象，请重新输入";
    	exit;
    }
    $rowsperpage=2;//每页有几名用户
    //一共分了多少页
    if ($num%$rowsperpage==0) {
        $totalpages=$num/$rowsperpage;
    }
    else
        $totalpages=ceil($num/$rowsperpage);
    //每页起始的用户
    $start=($page-1)*$rowsperpage;
    $sql1=$sql." limit $start,$rowsperpage";
    $result1=mysql_query($sql1);
    ?>
    <table class="table table-hover" align="center" width="60%">
    <caption>注册用户信息（共<?php echo $num;?>用户）</caption>
			<tr>
				<td>用户编号</td>
				<td>用户名</td>
				<td>性别</td>
				<td>生日</td>
				<td>头像</td>
				<td>电子邮件</td>
				<td>操作</td>
			</tr>
		<?php
    while($row=mysql_fetch_assoc($result1)){
    ?>     
         <tr>
				<td><?php echo $row["uid"]?></td>
				<td><?php echo $row["uname"]?></td>
				<td><?php if($row["gender"]==0){
					echo "男";}
					else echo "女"; ?></td>
				<td><?php echo $row["birthdate"]?></td>
				<td><img src="../images/<?php echo ($row["pic"])?>" width="80"  height="80"></td>
				<td><?php echo $row["email"]?></td>
				<td><a href="userEdit.php?uid=<?php echo $row["uid"]; ?>">修改</a>|<a href="doUserDelete.php?uid=<?php echo $row["uid"] ?>" onclick="return confirm('真的删除吗？')">删除</a></td>
			</tr>
<?php
    }
    
    //$row=mysql_fetch_assoc($result)从结果集中取得一条记录，￥row是一个关联数组，下表分别是数据库中的各字段名
    //var_dump($row);
    ?>

    </table>
    <h3 align="center">
        <?php 
            echo "共有".$num."名用户"."&nbsp"."共分".$totalpages."页"."&nbsp";
            if ($page==1) {
                echo "首页"."&nbsp";
            }
            else
                echo "<a href=?page=1>首页</a>"."&nbsp";
            if ($page==1) {
                echo "上一页"."&nbsp";
            }
            else
                echo "<a href=?page=".($page-1).">上一页</a>"."&nbsp";
            for ($i=1; $i<=$totalpages ; $i++) {
                echo "<a href=?page=$i>第".$i."页</a>"."&nbsp";
            }
            if ($page==$totalpages) {
                echo "尾页"."&nbsp";
            }
            else
                echo "<a href=?page=$totalpages>尾页</a>"."&nbsp";
            if ($page==$totalpages) {
                echo "下一页"."&nbsp";
            }
            else
                echo "<a href=?page=".($page+1).">下一页</a>"."&nbsp";
        ?>
    </h3>

   


<?php
  require_once('tpl/footer.php');
?>